package com.tianbing.adlottery.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.jubao.ejb.dao.CategoryDao;
import com.jubao.ejb.dao.UserDao;
import com.jubao.ejb.entity.Category;
import com.jubao.ejb.entity.User;
import com.tianbing.adlottery.helper.SkinUtils;

/**
 * MultiActionController for the image list/upload UI.
 * 
 * @author Conan Chen
 * @since 2006.12.15
 */
public class UserController extends MultiActionController {
	Logger logger = Logger.getLogger(UserController.class.getName());

	private String servantDetailView;

	private UserDao userDao;

	private CategoryDao categoryDao;

	private SkinUtils skinUtils;

	public ModelAndView viewServantDetail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(servantDetailView);
		Map model = mv.getModel();

		Long argsid = skinUtils.getParameterAreaCategorySysId(request);
		long usersid = ServletRequestUtils.getLongParameter(request, "usersid", -1);
		User user = userDao.find(usersid);
		if(user!=null){
			Category areaCategory = categoryDao.find(argsid);
			//get category primary trail
			List<Category> areaPrimaryCategoryTrail = null;
			if (areaCategory != null) {
				areaPrimaryCategoryTrail = categoryDao.getPrimaryCategoryTrail(argsid);
			}
			model.put("user",user);
			model.put("areaPrimaryCategoryTrail",areaPrimaryCategoryTrail);
		}

		return mv;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public void setServantDetailView(String servantDetailView) {
		this.servantDetailView = servantDetailView;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

}
